from matplotlib.image import imread
from sklearn.cluster import KMeans
import matplotlib.pyplot as plt 
im_data = imread('MLPractice\\dataset\\flower.jpg')
img_height = im_data.shape[0]
img_width = im_data.shape[1]
img_channel = im_data.shape[2]
x = im_data.reshape((img_height*img_width,img_channel))
print(x)
y = KMeans(n_clusters=5,random_state=42).fit(x)
processed_img = y.cluster_centers_[y.labels_].astype(int).reshape((img_height,img_width,img_channel))
print(processed_img)
plt.figure(figsize=(18,9))
plt.subplot(232)
plt.imshow(im_data)
plt.subplot(233)
plt.imshow(processed_img)
plt.show()



